package com.shopx.auth.controller;

import com.shopx.auth.bean.SysRole;
import com.shopx.auth.model.SysRoleModel;
import com.shopx.auth.service.ISysRoleService;
import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.controller.BaseController;
import com.shopx.base.dto.Result;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cmm.DTO.PageDTO;
import com.shopx.core.common.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lituo
 * @className: SysConfigController
 * @description: 角色
 * @date 2021/12/5 12:04 PM
 */
@RestController
@Slf4j
@RequestMapping(value = "/sysRole")
public class SysRoleController extends BaseController {

  @Autowired
  private ISysRoleService sysRoleService;

  @PostMapping(value = "/queryPageList")
  @ShopxParamAnno
  public Result<PageDTO> queryPageList(@RequestBody SysRoleModel sysRole) throws ShopxException {
    PageDTO<SysRoleModel> pageDTO = sysRoleService.getListPage(sysRole);
    return ResultUtil.ok(pageDTO);
  }

  /**
   * 查询编辑角色列表（分角色展示）
   *
   * @param sysRole
   * @return
   * @throws ShopxException
   */
  @PostMapping(value = "/queryEditList")
  public Result<List<SysRoleModel>> queryEditList(@RequestBody SysRoleModel sysRole) throws ShopxException {
    List<SysRoleModel> list = sysRoleService.queryEditList(sysRole);
    return ResultUtil.ok(list);
  }

  @PostMapping(value = "/insertOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<Integer> insertOne(@RequestBody SysRoleModel sysRole) throws ShopxException {
    int result = sysRoleService.insertSelective(sysRole);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/updateOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> updateOne(@RequestBody SysRoleModel sysRole) throws ShopxException {
    sysRoleService.updateByPrimaryKeySelective(sysRole);
    return ResultUtil.ok(true);
  }

  @PostMapping(value = "/selectByRoleCode")
  @ShopxParamAnno
  public Result<?> selectByRoleCode(@RequestBody SysRole sysRole) throws ShopxException {
    SysRole result = sysRoleService.selectByRoleCode(sysRole);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/queryOneByPrimaryKey")
  @ShopxParamAnno
  public Result<?> queryOneByPrimaryKey(@RequestBody SysRole sysRole) throws ShopxException {
    SysRoleModel result = sysRoleService.selectByPrimaryKey(sysRole);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/queryMatchUrl")
  @ShopxParamAnno
  public Result<?> queryMatchUrl(@RequestBody SysRole sysRole) {
    String result = sysRoleService.queryMatchUrl(sysRole);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/deleteChecked")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> deleteChecked(@RequestBody SysRole sysRole) throws ShopxException {
    int result = sysRoleService.deleteByPrimaryKey(sysRole);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/deleteBatch")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  public Result<?> deleteBatch(@RequestBody List<SysRole> list) {
    sysRoleService.deleteBatch(list);
    return ResultUtil.ok(true);
  }
}

